/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2024-11-01
 * Time: 19:30
 */
class Solution1 {
    public int search(int[] nums, int target) {
        //mid=left + (right - left)/3
        //用left移动思想来确定mid的位置，这种写法可以防溢出
        int left = 0 , right = nums.length-1 , mid = (left+right)/2;
        while(left<=right){
            if(nums[mid] < target){
                left = mid + 1 ;
                mid = (left+right)/2;
            }else if(nums[mid] > target){
                right = mid - 1;
                mid = (left+right)/2;
            }else{
                return mid;
            }
        }
        return -1;
    }
}
public class Test1 {
}
